package com.itheima.health.dao;

import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import com.itheima.health.pojo.Order;


@Mapper
public interface OrderSettingDao {

    /**
     * 根据月份查询
     *
     * @param firstDayOfMonth
     * @param lastDayOfMonth
     * @return
     */
    @Select("select * from t_ordersetting where orderDate between #{firstDayOfMonth} and #{lastDayOfMonth}")
    List<OrderSetting> selectByMonth(LocalDate firstDayOfMonth, LocalDate lastDayOfMonth);

    /**
     * 批量新增
     *
     * @param orderSettingListDb
     */
    void insert(@Param("orderSettingListDb") List<OrderSetting> orderSettingListDb);

    /**
     * 查询全部
     *
     * @return
     */
    @Select("select * from t_ordersetting")
    List<OrderSetting> findAll();

    /**
     * 更新
     *
     * @param orderSetting
     */
    void update(OrderSetting orderSetting);

    /**
     * 根据日期查询当天是否预约满
     *
     * @param orderDate
     * @return
     */
    @Select("select reservations from t_ordersetting where orderDate = #{orderDate}")
    int selectReservationsByOrderDate(Date orderDate);

    /**
     * 根据日期查询
     *
     */

    OrderSetting selectByOrderDate(@Param("orderDate") Date orderDate);

    /**
     * 根据id更新已预约人数
     *
     * @param orderSettingDb
     */
    @Update("update t_ordersetting set reservations = #{reservations} where id = #{id}")
    void updateReservations(OrderSetting orderSettingDb);

    /**
     * 根据日期查询已预约人数和
     *
     * @param firstDayOfMonth
     * @param lastDayOfMonth
     * @return
     */
    @Select("select sum(reservations) from t_ordersetting where orderDate between #{firstDayOfMonth} and #{lastDayOfMonth}")
    int selectReservations(String firstDayOfMonth, String lastDayOfMonth);

    /**
     * 根据日期查询已预约人数
     *
     * @param firstDayOfWeek
     * @param lastDayOfWeek
     * @return
     */
    @Select("select sum(reservations) from t_ordersetting where orderDate between #{firstDayOfWeek} and #{lastDayOfWeek}")
    int selectReservationsByDate(String firstDayOfWeek, String lastDayOfWeek);

    /**
     * 根据日期查询预约记录
     * @param orderDate
     */
    @Select("select * from t_ordersetting where orderDate = #{orderDate} ")
    OrderSetting selectByDate(String orderDate);

    /**
     * 在预约表中跟新人数加1
     */
    Order insertPeople(Integer id, int i);

    /**
     * 根据id跟新已经预约人数
     */
    void updateReservationsById(@Param("id") Integer id, @Param("reservations") int reservations);

    /**
     * 06新增
     * @param orderSetting
     */
    void add(OrderSetting orderSetting);

    /**
     * 06查找orderDate对应有无数据
     * @param orderDate
     * @return
     */
    int findCountByOrderDate(Date orderDate);

    /**
     *06_预约管理可预约单独设置
     * @param orderSetting
     */
    void editNumberByDate(OrderSetting orderSetting);
}
